// void, Obj me

Tower this;
Obj target;
bool bAttacked;

this = me.AsTower();
if (!.IsValid) return;

while(true){
	//pr("tower attack");
	target = .GetUITarget();
	
	if(target.IsAlive() && .IsValidTarget(target)) {
		//pr(target.AsUnit.class);
		if(.CanAttack(target)) {
			bAttacked = false;
			
			while(.Attack(target)) {
				bAttacked = true;
				target = .GetUITarget();
				if (!target.IsValid)
					break;
				if (!target.IsAlive)
					break;
				if (!.IsValidTarget(target))
					break;
				if (!.CanAttack(target))
					break;
				//pr(.health);	
				//######### MODUL GUARDIAN 1 START ###########
				if(target.AsUnit.IsHeirOf("EGuardian")){
					if(target.AsUnit.command != "engage" &&
					   target.AsUnit.command != "engage_unit_type"){
						if(rand(100) > 10){
							if(!target.AsUnit.BestTargetForPos.IsValid)
							if(target.AsUnit.health < target.AsUnit.maxhealth){
								target.AsUnit.Heal(500);
							}
						}
					}
				}
				//######### MODUL GUARDIAN 1 END ###########
				Sleep(100);
			}
			Sleep(500);
			if (bAttacked)
				continue;
		}
	}
	Sleep(500);
}